<title>分派维修单</title>
<script type="text/html" template lay-url="/admin/repair_records/{{d.params.id}}" lay-done="layui.data.done(d);">
    <form class="layui-form" action="" method="post" lay-filter="LAY-repair-form-update">
        <input type="hidden" name="id" value="{{d.result.id}}"/>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">维修员</label>
                <div class="layui-input-inline" id="LAY-system-repairman-tpl">

                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="LAY-repair-form-update">立即提交</button>
            </div>
        </div>

    </form>
</script>
<script type="text/html" id="LAY-system-repairman-select-tpl">
    <select name="repairId">
            <option value=""></option>
        {{#
            layui.each(d.result, function(index, item){
        }}
            <option value="{{item.id}}">{{ item.name }}</option>
        {{# });
        }}
    </select>
</script>
<script>
    layui.use(['admin', 'form'], function () {
        var $ = layui.$
            , admin = layui.admin
            , setter = layui.setter
            , layer = layui.layer
            , response = setter.response
            , form = layui.form

        form.on('submit(LAY-repair-form-update)', function (data) {
            admin.req({
                url: '/admin/repair_records/' + data.field.id + '/deliver'
                , traditional: true
                , type: 'put'
                , data: data.field
                , success: function (res) {
                    var statusCode = response.statusCode;
                    if (res[response.statusName] == statusCode.ok) {
                        layer.closeAll('page');
                        layer.msg('分派成功', {
                            icon: 1
                        });
                    }
                }
            });
            return false;
        });
    });
    var formData;
    layui.data.done = function (d) {
        layui.use(['form'], function () {
            var form = layui.form

            formData = d.result;

            layui.admin.req({
                url: "/admin/options?repairmen",
                dataType:"json",
                success:function(res) {
                    layui.laytpl(layui.$('#LAY-system-repairman-select-tpl').html()).render(res, function(html){
                        layui.$("#LAY-system-repairman-tpl").html(html);
                    });
                    form.render(null, 'LAY-repair-form-update'); //渲染该模板下的动态表单
                }
            })
        });
    };

</script>
